﻿#ifndef DEVICEDBMANAGER_H
#define DEVICEDBMANAGER_H
#include "SqliteDB.h"
#include "TableDBManager.h"
#include "Base/Model.h"
#include "Base/Command.h"

class DeviceDBManager
{
private:
    static DeviceDBManager* instance;
    DeviceDBManager();
    SqliteDB mydb;

public:
    static DeviceDBManager* getInstance() {
        static QMutex mutex; // 用于保证线程安全
        QMutexLocker locker(&mutex);
        if (instance == nullptr) {
            instance = new DeviceDBManager();
            instance->initDeviceInfo();
        }
        return instance;
    }

    void initDeviceInfo();
    bool containsDeviceInfo(QString type);
    bool containsUserName(QString name);
    QVariant getDeviceInfo(QString type);
    bool setDeviceInfo(QString type,QString value);
    bool getSubInfo(SubInfoModel &subinfo);
    bool getGoodsPosition(InOutCabCommand_Server cmdserver,InOutCabCommand_Board &cmdboard);
    bool getUserRole(QString name,int &role);
    bool getUserPwd(QString name,QString &pwd);
    bool setGoodsState(InOutCabCommand_Server,StorgeGoodsState);
    bool getGoodsState(InOutCabCommand_Server cmd,StorgeGoodsState &state);
    bool distributeGoods(InOutCabCommand_Server &cmd);
    TableDBManager mSubConfigDB;
    TableDBManager mPortConfigDB;
    TableDBManager mDeviceConfigDB;
    TableDBManager mGoodsInfoDB;
    TableDBManager mUserInfoDB;
    QString CurLoginedUser = "admin";
};

#endif // DEVICEDBMANAGER_H
